<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/25 0025
 * Time: 11:13
 */

namespace app\admin\controller;


use think\Controller;

class Index extends Controller
{
    public function index(){
//        $title = db("title")->select();
        $title = $this->getCateByPid(0);
        $this->assign("title",$title);
        return view("index");
    }
    public function welcome(){
//        $data = $this->getCateByPid(0);
//        dump($data);die;
        echo "hello world";
    }
    public function getCateByPid($pid)
    {
        $data = db("title")->where("pid", $pid)->select();
        $res  = [];
        //遍历 递归
        foreach ($data as $key => $value) {
            // 代码段：核心点
            $value['shop'] = $this->getCateByPid($value['id']);
            $res[]         = $value;
        }
        return $res;
    }
}